/*-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License.You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
	
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
	
The Original Code is Fever RS ( ActionScript 3 ) Framework code.
	
The Initial Developer of the Original Code is Romain Ecarnot.
Portions created by Initial Developer are Copyright (C) 2006
the Initial Developer. All Rights Reserved.
	
Contributor(s):
	
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-----------------------------------------------------------------------------*/

package fever.app.player 
{
	import flash.system.Capabilities;

	/**
	 * Host player implementation.
	 * 
	 * @author Romain Ecarnot
	 */
	final internal class HostPlayerImp implements IHostPlayer
	{
		//--------------------------------------------------------------------
		// Private properties
		//--------------------------------------------------------------------
		
		private var _major : int;
		private var _minor : int;
		private var _revision : int;
		private var _type : String;
		
		
		//--------------------------------------------------------------------
		// Public properties
		//--------------------------------------------------------------------
		
		/** 
		 * @inheritDoc
		 */
		public function get major() : int { return _major; }
		
		/** 
		 * @inheritDoc
		 */
		public function get minor() : int { return _minor; }
		
		/** 
		 * @inheritDoc
		 */
		public function get revision() : int { return _revision; }
		
		/** 
		 * @inheritDoc
		 */
		public function get type() : String { return _type; }
		
		
		
		//--------------------------------------------------------------------
		// Public API
		//--------------------------------------------------------------------
		
		/** 
		 * @inheritDoc
		 */
		public function isActiveX() : Boolean
		{
			return _type == "ActiveX";	
		}

		/** 
		 * @inheritDoc
		 */
		public function isAir() : Boolean
		{
			return _type == "desktop";	
		}

		/** 
		 * @inheritDoc
		 */
		public function isExternal() : Boolean
		{
			return _type == "External";	
		}
		
		/** 
		 * @inheritDoc
		 */
		public function isPlugin () : Boolean
		{
			return _type == "PlugIn";
		}
		
		/** 
		 * @inheritDoc
		 */
		public function isStandAlone () : Boolean
		{
			return _type == "StandAlone";
		}
		
		/** 
		 * @inheritDoc
		 */
		public function isCompliant( maj : int = 0, min : int = 0, 
			rev : int = 0 ) : Boolean
		{
			if( maj == 0 || min == 0 ) return false;
			
			if( _major < maj ) return false;
			if( _major > maj ) return true;
			if( _minor < min ) return false;
			if( _minor > min ) return true;
			if( _revision < rev) return false;
			
			return true;
		}
		
		/** 
		 * @inheritDoc
		 */
		public function isFullScreenCompliant() : Boolean
		{
			return isCompliant( 9,0,18 );
		}
		
		/** 
		 * @inheritDoc
		 */
		public function toVersionString() : String
		{
			return _major + '.' + _minor + '.' + _revision;
		}
		
		
		//--------------------------------------------------------------------
		// Private implementations
		//--------------------------------------------------------------------
		
		/** @private */
		function HostPlayerImp( )
		{
			_checkPlayer( );
		}
		
		private function _checkPlayer() : void
		{
			var v : Array = Capabilities.version.split( ' ' );
			var a : Array = v[1].split( ',' );
			
			_major = Number( a[0] );
			_minor = Number( a[1] );
			_revision = Number( a[2] );
			
			_type = Capabilities.playerType;
		}
		
	}
}